let btn  =$(".login")
let username =$("#username")
let password = $("#password")

btn.click(function(){
    lodo()
    .done(function(data){
        console.log(data);
        switch (data.code) {
            case 0:
                // errorTip(data.message);
                break
            case 1:
                console.log(data);
                alert("登录成功")
                // successTip(data.message);

                setTimeout(function(){
                     location.href = "./shouye.html"
                },1000)
                setCookie( "userid" , data.user.id );
                // setCookie("name","sdfsd")
                setCookie( "token" , data.token , {
                    expires : 1 
                });
                
                break
        }
    })
})

function lodo(){
  let options ={
      url:"http://127.0.0.1:8888/users/login",
      type:"POST",
      data:{
        username:`${username[0].value}`,
        password:`${password[0].value}`
      },
      datatype:`json`
  } 
  
  return $.ajax(options)
     
}
